﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;

namespace WorldBankBBS.Data
{
    public partial class Log
    {
        public static Log CreateLog(Guid logUID, string type, string message, DateTime timestamp)
        {
            var result = new Log() {LogUID = logUID, Message = message, Timestamp = timestamp, Type = type};

            return result;
        }

        public static void WriteLogEntry(string type, string message)
        {
            WriteLogEntry(type, message, DateTime.UtcNow);
        }

        public static void WriteLogEntry(string type, string message, DateTime timestamp)
        {
            var log = CreateLog(Guid.NewGuid(), type, message, timestamp);

            using (var entities = new ModelHelper())
            {
                entities.BeginNewContext();
                entities.AddToLogs(log);
                entities.Context.SaveChanges();
            }
        }
    }
}
